import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-house' }
    }]
  },
  {
    path: '/set',
    component: Layout,
    meta: { title: '基础设置', icon: 'el-icon-setting' },
    children: [
      {
        path: 'banner',
        name: 'banner',
        component: () => import('@/views/set/banner'),
        meta: { title: '轮播图' }
      },
      {
        path: 'department',
        name: 'department',
        component: () => import('@/views/set/department'),
        meta: { title: '部门管理' }
      },
      {
        path: 'recruit_level',
        name: 'recruit_level',
        component: () => import('@/views/set/recruit_level'),
        meta: { title: '招聘等级管理' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    meta: { title: '用户管理', icon: 'el-icon-user' },
    children: [
      {
        path: 'user_list',
        name: 'user_list',
        component: () => import('@/views/user/user-nornal'),
        meta: { title: '用户列表' }
      },
      {
        path: 'to_examine_list',
        name: 'to_examine_list',
        component: () => import('@/views/user/check-user'),
        meta: { title: '待审核用户' }
      },
      {
        path: 'refuse_user_list',
        name: 'refuse_user_list',
        component: () => import('@/views/user/del-refuse-user'),
        meta: { title: '已拒绝用户' }
      }
    ]
  },
  {
    path: '/rules',
    component: Layout,
    meta: { title: '规章制度', icon: 'el-icon-user' },
    children: [
      {
        path: 'rules-list',
        name: 'rules-list',
        component: () => import('@/views/rules/rules-list'),
        meta: { title: '规章制度列表' }
      },
      {
        path: 'rules-info',
        name: 'rules-info',
        component: () => import('@/views/rules/rules-info'),
        meta: { title: '新增规章制度' }
      },
      {
        path: 'rules-info-reset',
        name: 'rules-info-reset',
        component: () => import('@/views/rules/rules-info-reset'),
        meta: { title: '修改规章制度' },
        hidden: true
      }
    ]
  },
  {
    path: '/recruit_order',
    component: Layout,
    meta: { title: '招聘管理', icon: 'el-icon-document' },
    children: [
      {
        path: 'recruit_list',
        name: 'recruit_list',
        component: () => import('@/views/recruit-order/to-be-received'),
        meta: { title: '待接单' }
      },
      {
        path: 'receive_list',
        name: 'receive_list',
        component: () => import('@/views/recruit-order/receive-order'),
        meta: { title: '已接单' }
      },
      {
        path: 'recruiting',
        name: 'recruiting',
        component: () => import('@/views/recruit-order/recruiting'),
        meta: { title: '进行中' }
      },
      {
        path: 'recruit_entry',
        name: 'recruit_entry',
        component: () => import('@/views/recruit-order/entry'),
        meta: { title: '入职' }
      },
      {
        path: 'complete_recruit',
        name: 'complete_recruit',
        component: () => import('@/views/recruit-order/complete'),
        meta: { title: '已完成' }
      },
      {
        path: 'recruit_info',
        name: 'recruit_info',
        component: () => import('@/views/recruit-order/recruit-info'),
        meta: { title: '招聘详情' },
        hidden: true
      },
      {
        path: 'refuse_recruit',
        name: 'refuse_recruit',
        component: () => import('@/views/recruit-order/refuse'),
        meta: { title: '取消或拒绝' }
      }
    ]
  },
  {
    path: '/car_control',
    component: Layout,
    meta: { title: '用车管理', icon: 'el-icon-trophy' },
    children: [
      {
        path: 'driver_list',
        name: 'driver_list',
        component: () => import('@/views/carControl/driver_list'),
        meta: { title: '司机列表' }
      },
      {
        path: 'car_list',
        name: 'car_list',
        component: () => import('@/views/carControl/car-list'),
        meta: { title: '车辆管理' }
      },
      {
        path: 'car_order_list0',
        name: 'car_order_list0',
        component: () => import('@/views/carControl/order-list0'),
        meta: { title: '待接单' }
      },
      {
        path: 'car_order_list1',
        name: 'car_order_list1',
        component: () => import('@/views/carControl/order-list1'),
        meta: { title: '已接单' }
      },
      {
        path: 'car_order_list2',
        name: 'car_order_list2',
        component: () => import('@/views/carControl/order-list2'),
        meta: { title: '进行中' }
      },
      {
        path: 'car_order_list3',
        name: 'car_order_list3',
        component: () => import('@/views/carControl/order-list3'),
        meta: { title: '已完成' }
      },
      {
        path: 'car_order_list10',
        name: 'car_order_list10',
        component: () => import('@/views/carControl/order-list10'),
        meta: { title: '已拒绝' }
      }
    ]
  },
  {
    path: '/integral',
    component: Layout,
    meta: { title: '积分记录', icon: 'el-icon-trophy' },
    children: [
      {
        path: 'personal_integral',
        name: 'personal_integral',
        component: () => import('@/views/integral/user-integral'),
        meta: { title: '用户积分记录' }
      },
      {
        path: 'department_integral',
        name: 'department_integral',
        component: () => import('@/views/integral/department-integral'),
        meta: { title: '部门积分记录' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
